# coding=utf-8
from rest_framework import status
from rest_framework.test import APITestCase


class APITests(APITestCase):

    def test_qrocde(self):
        print('test API /qrcode/')
        url = '/qrcode/'
        long_url = 'http://h5.t.sohu.com/user/profile/em10dGVzdDAwMUBzb2h1LmNvbQ--'
        data = {'long_url': long_url}
        response = self.client.get(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        expect_short_url = 'h5bPGik7'
        expect_qrcode_url = 'http://2ed3559cebdf8.cdn.sohucs.com/qrcode/qrcode_h5bPGik7.png'
        self.assertEqual(response.data['data']['short_url'], expect_short_url)
        self.assertEqual(
            response.data['data']['qrcode_url'], expect_qrcode_url)

    def test_shorturl(self):
        print('test API /shorturl/')
        url = '/r/h5bPGik7'
        data = {}
        response = self.client.get(url, data, format='json')
        self.assertEqual(
            response.status_code, status.HTTP_301_MOVED_PERMANENTLY)

    def test_longurl(self):
        print('test API /longurl/')
        url = '/longurl/'
        data = {'short_url': 'http://qrcode.sce.sohuno.com/r/h5bPGik7'}
        response = self.client.get(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        expect_long_url = 'http://h5.t.sohu.com/user/profile/em10dGVzdDAwMUBzb2h1LmNvbQ--'
        self.assertEqual(response.data['data']['long_url'], expect_long_url)
